package com.myna.csv.scan;

import com.myna.csv.domain.PropertyStr;
import com.myna.csv.extractor.RelationShipPIExtract;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import static com.myna.csv.extractor.RelationShipPIExtract.filePIPathList;
import static com.myna.csv.initial.InitialProcessor.XmlPath;

/**
 * scan type = Q or O
 */
public class ScanRelationShipPIProcesser {
    public static final Logger LOGGER = LogManager.getLogger(ScanAllRDCFilesProcesser.class);

    List<File> filePathList = new ArrayList<>();
    int index = 0;

    public ScanRelationShipPIProcesser() {
        File file = new File(XmlPath);
        getFileList(file);
    }

    public void getFileList(File file) {
        File[] filePaths = file.listFiles();
        for (File file1 : filePaths) {
            if (file1.isDirectory()) {
                getFileList(file1);
            } else if (file1.isFile() && file1.getName().lastIndexOf(".gz") != -1) {
                filePathList.add(file1);
            }
        }
    }

    public void process() {
        File file = null;
        Long startTime = System.currentTimeMillis();
        RelationShipPIExtract extract = new RelationShipPIExtract();
        while (index < filePathList.size()) {
            file = filePathList.get(index);
            index++;
            Long one_startTime = System.currentTimeMillis();
            extract.extract(file);
            Long one_endTime = System.currentTimeMillis();
            LOGGER.info("one file scan cost time :" + (one_endTime - one_startTime));
        }

        PropertyStr.que_Flag = false;
        Long endTime = System.currentTimeMillis();
        LOGGER.info("Scan All Files type = O or Q  cost Time ： " + (endTime - startTime));
    }
}
